package com.example.spring5.bean;

public class UserFactory{
    public static UserDao getDao1(){
        return new UserDao();
    }
    public static UserDao getDao2(String a){
        Class clazz = null;
        try {
            clazz = Class.forName(a);//for Name  名副其实
            //classPath这个类必须有空参构造器
            return (UserDao) clazz.newInstance();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }finally {
            return null;
        }
    }
}

